/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package frm.billingAndPaymentProcessing.managedbean;

import frm.billingAndPaymentProcessing.entity.InvoiceEntity;
import frm.billingAndPaymentProcessing.session.InvoiceSessionBean;
import java.io.IOException;
import javax.ejb.EJB;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;

/**
 *
 * @author xhx
 */
@ManagedBean
@ViewScoped
public class UpdatePaymentManagedBean {
private InvoiceEntity invoice;
private double amountPaidByCompany;
@EJB
InvoiceSessionBean invoiceSessionBean;
    /** Creates a new instance of UpdatePaymentManagedBean */
    public UpdatePaymentManagedBean() {
       
    }
    public void initView(){
           if (invoice == null) { 
           invoice = (InvoiceEntity) FacesContext.getCurrentInstance().getExternalContext().getFlash().get("invoice");
        }  
    }
    public void updatePayment() throws IOException{
        //***************************************other changes*************************
          invoice.addAmountPaid(getAmountPaidByCompany());  
          invoiceSessionBean.saveChanges(invoice);
          FacesContext.getCurrentInstance().getExternalContext().getFlash().put("message", "Update is Made Successfully");
          FacesContext.getCurrentInstance().getExternalContext().getFlash().put("invoice", invoice);
          FacesContext.getCurrentInstance().getExternalContext().redirect("displayInvoice.xhtml");
    }

    public double getAmountPaidByCompany() {
        return amountPaidByCompany;
    }

    public void setAmountPaidByCompany(double amountPaidByCompany) {
        this.amountPaidByCompany = amountPaidByCompany;
    }
}
